package com.zlp.partice;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Day20211201 {


    @Test
    public void rr(){

    }

    public String[] findRelativeRanks(int[] score) {
        int len = score.length;
        int[] temp = new int[len];
        String[] str = new String[len];
        System.arraycopy(score,0,temp,0,len);
        Arrays.sort(temp);
        Map<Integer,String> map = new HashMap<>();
        for (int i=len-1;i>=0;i--){
          map.put(temp[i],String.valueOf(len-i));
          if(i == len-1)  map.put(temp[len-1],"Gold Medal");
          if(i == len-2)  map.put(temp[len-2],"Silver Medal");
          if(i == len-3)  map.put(temp[len-3],"Bronze Medal");
        }
        for (int i=0;i<len;i++){
            str[i] = map.get(score[i]);
        }
        return str;
    }

    public int sum(int[] nums,int k){
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        int ret = 0;
        for (int val:nums) queue.add(val);
        while (k-->0){
            Integer cur = queue.poll();
            queue.offer(-cur);
        }
        Iterator<Integer> iterator = queue.iterator();
        while (iterator.hasNext()) ret += iterator.next();
        return ret;
    }

    public String ee(String s, int k) {
        for (int i = 0; i < s.length(); i++) {
            if (i == s.length() - 1 && k == 0) {
                return s;
            }
            if (s.charAt(i) == ' ') {
                k--;
                if (k == 0) {
                    return s.substring(0, i);
                }
            }
        }
        return null;
    }

}
